home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC02BusyBox / BusyBox.c / UEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-25  |  3.7 KB  |  135 lines  |  [04] ASCII Text (0x0000)

  1. /**********************************************************************
  2. *
  3. * busybox uevent.c -- Version 3.0 
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements the 
  12. * main event loop used by the busybox program.
  13. *
  14. **********************************************************************/
  15.  
  16. #include <types.h>
  17. #include <locator.h>
  18. #include <quickdraw.h>
  19. #include <event.h>
  20. #include <menu.h>
  21. #include <window.h>
  22. #include "busybox.h"
  23.  
  24. extern WmTaskRec        event;
  25. extern unsigned int     quitFlag;
  26.  
  27. static GrafPortPtr  lastWindow;         /* This private global is used in checkFrontW()
  28.                                         ** to prevent extra work when the windows
  29.                                         ** have not changed.  It is initialized
  30.                                         ** at the beginning of mainEvent().
  31.                                         */
  32.  
  33. /**********************************************************************
  34. *
  35. * doControls
  36. *
  37. * This procedure is called when an inControl message is returned
  38. * by TaskMaster.
  39. *
  40. * When this routine gets control, the ID of the control that was
  41. * hit is in TaskDATA4.  The control handle is in TaskData2 and
  42. * the part code is in taskData 3.
  43. *
  44. **********************************************************************/
  45. void    doControls()
  46. {
  47.     unsigned int    theID;
  48.  
  49.     theID = event.wmTaskData4;
  50.  
  51.     if ((ButButtonsID <= theID) && (theID <= Prog6ID)) {
  52.         openThisWindow(theID);
  53.     }
  54. }
  55.  
  56.  
  57.  
  58. /**********************************************************************
  59. *
  60. * checkFrontW
  61. *
  62. * This routine checks the front window to see if any changes need
  63. * to be made to the menu items.
  64. *
  65. * We do this so that the edit items are only active when a desk
  66. * accessory is active.
  67. *
  68. **********************************************************************/
  69. void    checkFrontW()
  70. {
  71.     GrafPortPtr     theWindow;
  72.  
  73.     theWindow = FrontWindow();
  74.         /* Get the front window into local storage.*/
  75.     
  76.     if (theWindow == lastWindow) return;
  77.         /* If the lastWindow is this window, we are all set. */
  78.     
  79.     /* If there are no windows, everything should be disabled */
  80.     if (!theWindow) {
  81.         SetMenuFlag(0x0080, EditMenuID);
  82.         DrawMenuBar();
  83.     } 
  84.     else {
  85.         /* Otherwise we look at the window and see what to do. */
  86.         if (GetSysWFlag(theWindow)) { 
  87.             SetMenuFlag (0xFF7F, EditMenuID);       /* Set up for da windows. */
  88.             DrawMenuBar();
  89.         }
  90.         else {
  91.             SetMenuFlag (0x0080, EditMenuID);       /* Set up for our windows. */
  92.             DrawMenuBar();
  93.         }
  94.     }
  95.  
  96.     lastWindow = theWindow;     /* Remember this for next time. */
  97. }
  98.  
  99.  
  100.  
  101. /**********************************************************************
  102. *
  103. * mainEvent
  104. *
  105. * This is the main part of the program.  The program cycles in this
  106. * loop until the user choose select.
  107. *
  108. **********************************************************************/
  109. void    mainEvent()
  110. {
  111.     unsigned int    code;
  112.  
  113.     event.wmTaskMask = 0x001FFFFF;          /* Allow TaskMaster to do everything.   */
  114.     quitFlag         = 0;                   /* Done flag will be set by Quit item.  */
  115.     lastWindow       = NULL;                /* Init this for checkFrontW().         */
  116.  
  117.     for (;;) {
  118.         checkFrontW();
  119.         code = TaskMaster(0xFFFF, &event);
  120.         switch(code) {
  121.             case wInGoAway:
  122.                 doCloseTop();
  123.                 break;
  124.             case wInSpecial:
  125.             case wInMenuBar:
  126.                 doMenu();
  127.                 break;
  128.             case wInControl:
  129.                 doControls();
  130.                 break;
  131.         }
  132.         if (quitFlag) break;
  133.     }
  134. }
  135.